<%@ page import="java.util.ArrayList" %>
<%@ page import="com.resataurant.Entity.Dish" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="javax.xml.namespace.QName" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>餐厅管理系统登录解密</title>
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <!-- 引入 layui.css -->
    <link href="//unpkg.com/layui@2.9.10/dist/css/layui.css" rel="stylesheet">
    <!-- 引入 layui.js -->
    <script src="//unpkg.com/layui@2.9.10/dist/layui.js"></script>
</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <button class="btn btn-default"><a href="${pageContext.request.contextPath}/user.jsp" >返回到上一页</a></button>
            <%
                HashMap<String, Dish> cart = (HashMap<String, Dish>) request.getSession().getAttribute("cart");
                String cartres = (String) request.getSession().getAttribute("buyCartres");
                if(cartres!=null&&cartres.equals("购买成功")){
                    //代表成功
                    out.write("<script>\n" +
                            "    alert(\"付款成功\")\n" +
                            "</script>");
                }
                if(cartres!=null&&cartres.equals("付款失败")){
                    out.write("<script>\n" +
                            "    alert(\"付款失败\")\n" +
                            "</script>");
                }
            %>

            <table class="table">
                <thead>
                <tr>
                    <th>
                        商品名称
                    </th>
                    <th>
                        商品价格
                    </th>
                    <th>
                        商品数量
                    </th>
                    <th>
                        清空
                    </th>
                </tr>
                </thead>
                <tbody>

                <%
                    if(cart!=null) {
                        out.write("<form class=\"layui-form\" role=\"form\" method=\"post\" action=\"" + request.getContextPath() + "/BuyDishServlet?method=buyCartAll\">");
                        for (Dish dish : cart.values() ){

                            out.write(" <tr>");
                            out.write("<td>" + dish.getDishName() + "</td>");
                            out.write("<td>" + dish.getDishPrice() + "</td>");
                            out.write("<td><input type=\"number\" name=\""+dish.getDishId()+"\" lay-affix=\"number\" placeholder=\"\" value=\"" + dish.getW_num() + "\" class=\"layui-input\"></td>");
                            out.write("<td><a class=\"btn btn-warning\" href=\"BuyCartServlet?id=" + dish.getDishId() + "&method=del\">清除</a></td>");
                            out.write(" </tr>");

                        }
                        out.write("</div>");
                    }else{
                        out.write(" <tr>");
                        out.write("<td>购物车为空</td>");
                        out.write(" </tr>");
                    }
                %>

                </tbody>
            </table>
            <% if(cart!=null && !cart.isEmpty()){ %>
            <button class="layui-btn" type="submit">付款</button>
            <%--<button class="layui-btn layui-btn-fluid" type="submit">全部付款</button>--%>
            <% } %>
        </div>
    </div>
</div>

</body>

</html>
